//
//  BIZSitcomListCoverView.m
//  biz
//
//  Created by zhangfuwei on 2017/3/25.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZSitcomListCoverView.h"

@implementation BIZSitcomListCoverView{
    UIImageView *_coverBgView;
    UIButton    *_startBtn;
}

- (instancetype)initWithCoverURLString:(NSString *)cover startBlock:(BIZSitcomListCoverViewStartBlock)startBlock
{
    self = [super init];
    if (self) {
        _coverURLStr = cover;
        _startBlock = startBlock;
        [self loadUI];
    }
    return self;
}

- (void)loadUI {
    
    _coverBgView = [[UIImageView alloc] init];
    [_coverBgView sd_setImageWithURL:[NSURL URLWithString:_coverURLStr] placeholderImage:[UIImage imageNamed:@"movie_cover"]];

    _startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_startBtn addTarget:self action:@selector(startPlay) forControlEvents:UIControlEventTouchUpInside];
    [_startBtn setBackgroundImage:[UIImage imageNamed:@"movie_start"] forState:UIControlStateNormal];
    
    [self addSubview:_coverBgView];
    [self addSubview:_startBtn];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    [_startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.equalTo(@32);
        make.center.equalTo(self);
    }];
    
    [_coverBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
}

-(void)setCoverURLStr:(NSString *)coverURLStr {
    _coverURLStr = coverURLStr;
    [_coverBgView sd_setImageWithURL:[NSURL URLWithString:coverURLStr] placeholderImage:[UIImage imageNamed:@"movie_cover"]];
    [self layoutIfNeeded];
}

- (void)startPlay {
    _startBlock ? _startBlock() : nil;
}
@end
